package com.code.p9.代理模式.JDK的动态代理;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * 描述: describe
 *
 * @author CodeYang_Site
 * @version 2021/6/7 1:15
 */
public class JDK的动态代理 {

    public static void main(String[] args) {

        /**
         * JDK 的动态代理
         */
        ISubjectOA subjectOA = new SubjectOAIm();
        //subjectOA = (ISubjectOA) Proxy.newProxyInstance(JDK的动态代理.class.getClassLoader(), new Class[]{ISubjectOA.class}, new SubjectHandelProxy(subjectOA));
        ISubjectOA finalSubjectOA = subjectOA;
        subjectOA = (ISubjectOA) Proxy.newProxyInstance(JDK的动态代理.class.getClassLoader(), new Class[]{ISubjectOA.class}, new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("前置");
                Object invoke = method.invoke(finalSubjectOA, args);
                System.out.println("后置");
                return invoke;
            }
        });
        subjectOA.see();


    }
}
